﻿
function PostComment(postObj, modelId) {
    var score = postObj.find(".Score input").val();
    var contentId = postObj.attr("ContentID");
    var content = postObj.find(".Content").val();
    var replyId = postObj.attr("ReplyID");

    if (content == "") {
        alert("内容不为空！");
        return;
    }
    if (content.length > 300) {
        alert("评论内容字数不能超过300！");
        return;
    }

    var parameters = {
        ModelID: modelId,
        ContentID: contentId,
        ReplyID: replyId,
        Score: score,
        Content: escape(content)
    };


    $.ajax({
        type: "POST",
        url: "/api/Comment/Post",
        data: parameters,
        success: function (res) {
            if (res.Err.length == 0) {
                window.location = window.location;
            } else {
                alert(res.Err);
            }
        }
    });
}

function SupportOrOppose(id, support, obj) {
    $.ajax({
        type: "POST",
        url: "/api/Comment/Support?id=" + id + "&support=" + support,
        success: function (comment) {
            if (null == data) {
                alert("评论可能已经被管理员删除。");
            }

            if (true == support) {
                $(obj).text("支持(" + comment.Support + ")");
            }
            else {
                $(obj).text("反对(" + comment.Oppose + ")");
            }
        }
    });
}
function Commentonkeyup() {
    if (event.ctrlKey && (10 == event.keyCode || 13 == event.keyCode))
        PostComment();
    else
        Commentonchange($('#Content'));
}
function Commentonchange(obj) {
    if (obj)
        $('#spanCommentContentLength').html($(obj).val().length);
}